﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using Common.Lib.Assembly;
using NHibernate;
using NHibernate.Cfg;

namespace InnovTech.Persistence
{
    //The regular way to create ISessionFactory. Something like fluent should be specially handled.
    public abstract class SessionFactoryBuilderBase<TDatabaseInfo> : ISessionFactoryBuilder<TDatabaseInfo>
        where TDatabaseInfo : INHDatabaseInfo
    {
        #region Fields
        

        #endregion

        #region Properties
        public TDatabaseInfo DatabaseInfo { get; private set; }
        #endregion

        #region ctor
        public SessionFactoryBuilderBase(TDatabaseInfo dbInfo)
        {
            DatabaseInfo = dbInfo;
        }
        #endregion

        #region Methods

        #region ISessionFactoryBuilder Members
        public NHibernate.ISessionFactory BuildSessionFactory()
        {
            return CreateSessionFactory(DatabaseInfo);
        }

        public Configuration BuildConfiguration()
        {
            return GetConfiguration(DatabaseInfo);
        }

        #endregion

        protected abstract Configuration GetConfiguration(TDatabaseInfo dbInfo);
        protected virtual ISessionFactory CreateSessionFactory(TDatabaseInfo dbInfo)
        {
            Configuration config = BuildConfiguration();
            return config.BuildSessionFactory();
        }

        #endregion



    }
}
